<?php
namespace app\index\model;

use think\Model;
use think\DB;

class VideoList extends Model
{
    //获取某类所有的视频信息
    public function getVideoList($page,$class_type){
//        return DB::name('video_list')->page("$page,10")->select();
        return DB::table('hy_video_list')
            ->alias('vl')
            ->join('hy_video_class vc','vc.id= vl.classtype')
            ->where('vc.classtype',$class_type)
            ->page("$page,10")
            ->select();
    }

    //获取一个视频的信息
    public function getOneVideo($vid){
        return DB::name('video_list')->where('vid',$vid)->find();
    }

    //增加播放次数
    public function addVideoPlayNum($vid){
        return DB::name('video_list')->where('vid',$vid)->setInc('playnum');
    }

    //获取某类视频的总数
    public function getVideoListCount($class_type){
        return DB::table('hy_video_list')
            ->alias('vl')
            ->join('hy_video_class vc','vc.id= vl.classtype')
            ->where('vc.classtype',$class_type)
            ->count();
    }

    //搜索
    public function getSearchList($key,$page){
        $map['title'] = ['like',"%$key%"];
        return DB::name('video_list')->page("$page,6")->where($map)->select();
    }

    //搜索结果总数
    public function getSearchListCount($key){
        $map['title'] = ['like',"%$key%"];
        return DB::name('video_list')->where($map)->count();
    }

    //推荐视频
    public function getRecommendedVideo($classtype){
        return DB::name('video_list')->where('classtype',$classtype)->order('playnum desc')->limit(4)->select();
    }

    public function getLoveVidApp($page){
        return DB::name('vr_love_vid')->page("$page,6")->select();
    }


}